package com.sinosoft.emplmis.labor.web;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.sinosoft.emplmis.labor.entity.JobInfoEntity;
import com.sinosoft.emplmis.labor.entity.LaborInfoEntity;
import com.sinosoft.emplmis.labor.entity.PersonInfoEntity;
import com.sinosoft.emplmis.labor.entity.UnemployedInfoEntity;
import com.sinosoft.emplmis.labor.service.LaborInfoService;
import com.sinosoft.emplmis.labor.web.dto.LaborInfoData;
import com.sinosoft.emplmis.labor.web.dto.LaborSearchData;
import com.sinosoft.framework.core.api.domain.UserOrgData;
import com.sinosoft.framework.core.api.service.UserOrgService;
import com.sinosoft.framework.core.common.exception.BusinessException;
import com.sinosoft.framework.core.common.utils.ResultJson;
import com.sinosoft.framework.security.utils.SecurityUtil;

/**
 * 劳动力信息管理controller 
 * @author liux
 *
 */
@Controller
@RequestMapping("labor/management")
public class LaborManagerController {
	
	ObjectMapper mapper = new ObjectMapper();
	
	/**
	 * 劳动力信息Service
	 */
	@Autowired
	private LaborInfoService laborInfoService;
	
	/**
	 * 劳动力人员信息页面跳转
	 * @return
	 */
	@RequestMapping(value="/laborInfoManager", method = RequestMethod.GET)
	public String laborInfoManager(){
		return"labor/laborInfo";
	}
	
	/**
	 * 失联人员信息页面跳转
	 * @return
	 */
	@RequestMapping(value="/loseTouchInfoManager", method = RequestMethod.GET)
	public String loseTouchInfoManager(){
		return"labor/loseTouchInfo";
	}
	
	/**
	 * 获取劳动力人员信息
	 * @return
	 */
	@RequestMapping(value="/getLaborInfoList")
	@ResponseBody
	public ResultJson getLaborInfoList(LaborSearchData data){
		ResultJson result = new ResultJson();
		String success="";
		String message="";
		List<LaborInfoData> resultList = new ArrayList<LaborInfoData>();
		List<LaborInfoEntity> laborInfoEntityList = new ArrayList<LaborInfoEntity>();
		try {
			laborInfoEntityList = laborInfoService.selectAll(data);
			for (LaborInfoEntity laborInfoEntity : laborInfoEntityList) {
				LaborInfoData laborInfoData = new LaborInfoData();
				//劳动力信息实体类转化为劳动力信息dto
				laborInfoData.toEntityData(laborInfoData,laborInfoEntity);
				resultList.add(laborInfoData);
			}
			result.setTotal(laborInfoService.count(data));
			result.setRows(resultList);
			success= ResultJson.SUCCESS_YES;
			message= ResultJson.MESSAGE;
		} catch (Exception e) {
			success= ResultJson.SUCCESS_NO;
			message= "获取失败";
			e.printStackTrace();
		}finally {
			result.setSuccess(success);
			result.setMessage(message);
		}
		return result;
	}
	
	/**
	 * 获取失联人员信息
	 * @return
	 */
	@RequestMapping(value="/getLoseTouchInfoList", method = RequestMethod.POST)
	@ResponseBody
	public ResultJson getLoseTouchInfoList(LaborSearchData data){
		ResultJson result = new ResultJson();
		String success="";
		String message="";
		List<LaborInfoData> resultList = new ArrayList<LaborInfoData>();
		List<LaborInfoEntity> laborInfoEntityList = new ArrayList<LaborInfoEntity>();
		try {
			laborInfoEntityList = laborInfoService.selectLoseContact(data);
			for (LaborInfoEntity laborInfoEntity : laborInfoEntityList) {
				LaborInfoData laborInfoData = new LaborInfoData();
				//劳动力信息实体类转化为劳动力信息dto
				laborInfoData.toEntityData(laborInfoData,laborInfoEntity);
				resultList.add(laborInfoData);
			}
			result.setTotal(laborInfoService.countlose(data));
			result.setRows(resultList);
			success= ResultJson.SUCCESS_YES;
			message= ResultJson.MESSAGE;
		} catch (Exception e) {
			success= ResultJson.SUCCESS_NO;
			message= "获取失败";
			e.printStackTrace();
		}finally {
			result.setSuccess(success);
			result.setMessage(message);
		}
		return result;
	}
	
/*
	*//**
	 * 查看当年实现就业信息
	 *//*
	@RequestMapping(value="/getjobInfoList", method = RequestMethod.POST)
	@ResponseBody
	public List<JobInfoEntity> selectRealize(){
		List<JobInfoEntity> resultList = new ArrayList<JobInfoEntity>();
		resultList = jobInfoService.selectRealize();
		return resultList;
		
	}
	*//**
	 * 获取就业困难人员信息
	 *//*
	@RequestMapping(value="/unemployedInfoList", method = RequestMethod.POST)
	@ResponseBody
	public List<UnemployedInfoEntity> selectAll(){
		List<UnemployedInfoEntity> resultList = new ArrayList<UnemployedInfoEntity>();
		resultList = unemployedInfoService.selectAll();
		return resultList;
		
	}*/
	
	
	/**
	 * 添加劳动力人员信息
	 * @return
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value="/insertLaborInfo", method = RequestMethod.POST)
	@ResponseBody
	public String insertLaborInfoList (LaborInfoData record){
		String result = "";
		ResultJson resultJson = new ResultJson();
		try {
			laborInfoService.saveLaborInfo(record);
			resultJson.setSuccess(ResultJson.SUCCESS_YES);
			resultJson.setMessage(ResultJson.MESSAGE);
		} catch (BusinessException be) {
			resultJson.setSuccess(ResultJson.SUCCESS_NO);
			resultJson.setMessage(be.getMessage());
			be.printStackTrace();
		} catch (Exception e) {
			resultJson.setSuccess(ResultJson.SUCCESS_NO);
			resultJson.setMessage("保存失败");
			e.printStackTrace();
		}finally{
			try {
				result = mapper.writeValueAsString(resultJson);
			}catch (IOException e) {
				e.printStackTrace();
			}
			return result;
		}
		
	}
	
	@Autowired
	private UserOrgService userOrgService;
	
	/**
	 * 根据用户名获取用户机构信息
	 * @param Id
	 * @return
	 */
	@RequestMapping(value="/getUserOrg", method = RequestMethod.POST)
	@ResponseBody
	public String getUserOrg(@RequestParam("userName") String userName){
		//String userOrg = request.getAttribute("loginName");
//		String userOrg = request.getParameter("loginName");
		
		Session session = SecurityUtils.getSubject().getSession();
		//用户机构信息
		UserOrgData userOrgData = (UserOrgData) session.getAttribute("userOrg");
		if(userOrgData==null){
			throw new BusinessException("当前用户没有设定社区");
		}

		
		return SecurityUtil.getLoginName();
	}
	
	@Autowired  
	private  HttpServletRequest request; 
	
	/**
	 * 导入劳动力人员信息
	 * @return
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value="/importLaborData", method = RequestMethod.POST)
	@ResponseBody
	public String importLabor (){	
		String result = "";
		ResultJson resultJson = new ResultJson();
		LaborInfoData record = null;
		
		ServletFileUpload upload = new ServletFileUpload();
		FileItemIterator iter = null;
    	InputStream is = null;
    	int i = 1;
    	
    	try {
			iter = upload.getItemIterator(request);
			
			while (iter.hasNext()){
				FileItemStream item = iter.next();
			    is = item.openStream();
			    
			    if (!item.isFormField()){ //表单中的文件上传字段
			    	String filename = item.getName();
			    	System.out.println("上传excel文件名："+filename);
			    	
			    	if(filename != null && !filename.equals("")){
			    		Workbook wb = new HSSFWorkbook(is);   //上传文件以".xls"结尾
			            
			            HSSFSheet sheet = (HSSFSheet) wb.getSheetAt(0);
			            int rownum = sheet.getPhysicalNumberOfRows()-1; //数据记录条数，去掉表头
			            System.out.println("数据记录条数："+rownum);
			            int colnum=sheet.getRow(0).getPhysicalNumberOfCells();
			            System.out.println("数据列数："+colnum);
			            
			            HSSFCell cell = null;	
			            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
			            
			            for(;i<=rownum;i++){
			            	record = new LaborInfoData();
			            	
			            	//姓名
			            	cell = sheet.getRow(i).getCell(1);
			            	if(cell!=null && cell.getCellType() != HSSFCell.CELL_TYPE_BLANK){
			            		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
			            		record.setName(cell.getStringCellValue());
			            	}
			            	
			            	//性别
			            	cell = sheet.getRow(i).getCell(2);
			            	if(cell!=null && cell.getCellType() != HSSFCell.CELL_TYPE_BLANK){
			            		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
			            		record.setSex(cell.getStringCellValue());
			            	}
			            	
			            	//身份证号
			            	cell = sheet.getRow(i).getCell(3);
			            	if(cell!=null && cell.getCellType() != HSSFCell.CELL_TYPE_BLANK){
			            		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
			            		record.setIdcard(cell.getStringCellValue());
			            	}
			            	
			            	//学历
			            	cell = sheet.getRow(i).getCell(4);
			            	if(cell!=null || cell.getCellType() != HSSFCell.CELL_TYPE_BLANK){
			            		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
			            		record.setEducation(cell.getStringCellValue());
			            	}
			            	
			            	//联系方式
			            	cell = sheet.getRow(i).getCell(5);
			            	if(cell!=null || cell.getCellType() != HSSFCell.CELL_TYPE_BLANK){
			            		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
			            		record.setPhone(cell.getStringCellValue());
			            	}
			            	
			            	//就业状态
			            	cell = sheet.getRow(i).getCell(6);
			            	if(cell!=null || cell.getCellType() != HSSFCell.CELL_TYPE_BLANK){
			            		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
			            		record.setStatus(cell.getStringCellValue());
			            	}
			            	
			            	//所在单位
			            	cell = sheet.getRow(i).getCell(7);
			            	if(cell!=null || cell.getCellType() != HSSFCell.CELL_TYPE_BLANK){
			            		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
			            		record.setCompany(cell.getStringCellValue());
			            	}
			            	
			            	//失业时间
			            	/*cell = sheet.getRow(i).getCell(8);
			            	if(cell!=null || cell.getCellType() != HSSFCell.CELL_TYPE_BLANK){
			            		cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
			            		record.setUnemploymentdate(cell.getDateCellValue());
			            	}*/
			            	cell = sheet.getRow(i).getCell(8);
			            	if(cell!=null || cell.getCellType() != HSSFCell.CELL_TYPE_BLANK){
			            		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
			            		record.setUnemploymentdate(cell.getStringCellValue());
			            	}
			            	
			            	//街道
			            	cell = sheet.getRow(i).getCell(7);
			            	if(cell!=null || cell.getCellType() != HSSFCell.CELL_TYPE_BLANK){
			            		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
			            		record.setCompany(cell.getStringCellValue());
			            	}
			            	
			            	//社区
			            	cell = sheet.getRow(i).getCell(7);
			            	if(cell!=null || cell.getCellType() != HSSFCell.CELL_TYPE_BLANK){
			            		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
			            		record.setCompany(cell.getStringCellValue());
			            	}
			            	
//			            	laborInfoService.saveLaborInfo(record);
			            	for(int j=0;j<=colnum;j++){
			            		cell = sheet.getRow(i).getCell(j);
			            		if(cell==null){
			            			System.out.print("\t\t");			            			
			            		} else{
			            			if(j==8)
				            			System.out.print(df.format(cell.getDateCellValue())+"\t");
				            		else{
				            			cell.setCellType(HSSFCell.CELL_TYPE_STRING);
						            	System.out.print(cell.getStringCellValue()+'\t');					            			
				            		}			            			
			            		}	            		
			            	}
			            	System.out.println();
			            	
			            } //for循环
			            
			            resultJson.setSuccess(ResultJson.SUCCESS_YES);
			        	resultJson.setMessage("导入数据成功");
			            	
			    	} 
			      }			    			    		
			    }
		} catch (FileUploadException e1) {
			resultJson.setSuccess(ResultJson.SUCCESS_NO);
			resultJson.setMessage(e1.getMessage());
			e1.printStackTrace();
			System.out.println("导入第"+i+"条数据时发生异常：FileUploadException");
		} catch (IOException e1) {
			resultJson.setSuccess(ResultJson.SUCCESS_NO);
			resultJson.setMessage(e1.getMessage());
			e1.printStackTrace();
			System.out.println("导入第"+i+"条数据时发生异常：IOException");
		} catch (Exception e1){
			resultJson.setSuccess(ResultJson.SUCCESS_NO);
			resultJson.setMessage(e1.getMessage());
			e1.printStackTrace();
			System.out.println("导入第"+i+"条数据时发生异常：Exception");		
		} finally{
			try {
				result = mapper.writeValueAsString(resultJson);
			}catch (IOException e) {
				e.printStackTrace();
				System.out.println("写入result信息时发生异常！");
			}
			return result;
		}
    	
	}
	
//	/*
//	 * 导入劳动力信息
//	 */
//	@RequestMapping(value="/importLaborData")
//	@ResponseBody
//	public ModelAndView importLaborData(HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException{
//		String result = "";
//		ResultJson resultJson = new ResultJson();
//		LaborInfoData record = null;
//		
//		ServletFileUpload upload = new ServletFileUpload();
//		FileItemIterator iter = null;
//    	InputStream is = null;
//    	int i = 1;
//    	
//    	try {
//			iter = upload.getItemIterator(request);
//			
//			while (iter.hasNext()){
//				FileItemStream item = iter.next();
//			    is = item.openStream();
//			    
//			    if (!item.isFormField()){ //表单中的文件上传字段
//			    	String filename = item.getName();
//			    	System.out.println("上传excel文件名："+filename);
//			    	
//			    	if(filename != null && !filename.equals("")){
//			    		Workbook wb = new HSSFWorkbook(is);   //上传文件以".xls"结尾
//			            
//			            HSSFSheet sheet = (HSSFSheet) wb.getSheetAt(0);
//			            int rownum = sheet.getPhysicalNumberOfRows()-1; //数据记录条数，去掉表头
//			            System.out.println("数据记录条数："+rownum);
//			            int colnum=sheet.getRow(0).getPhysicalNumberOfCells();
//			            System.out.println("数据列数："+colnum);
//			            
//			            HSSFCell cell = null;	
//			            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
//			            
//			            for(;i<=rownum;i++){
//			            	record = new LaborInfoData();
//			            	
//			            	//姓名
//			            	cell = sheet.getRow(i).getCell(1);
//			            	if(cell!=null && cell.getCellType() != HSSFCell.CELL_TYPE_BLANK){
//			            		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
//			            		record.setName(cell.getStringCellValue());
//			            	}
//			            	
//			            	//性别
//			            	cell = sheet.getRow(i).getCell(2);
//			            	if(cell!=null && cell.getCellType() != HSSFCell.CELL_TYPE_BLANK){
//			            		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
//			            		record.setSex(cell.getStringCellValue());
//			            	}
//			            	
//			            	//身份证号
//			            	cell = sheet.getRow(i).getCell(3);
//			            	if(cell!=null && cell.getCellType() != HSSFCell.CELL_TYPE_BLANK){
//			            		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
//			            		record.setIdcard(cell.getStringCellValue());
//			            	}
//			            	
//			            	//学历
//			            	cell = sheet.getRow(i).getCell(4);
//			            	if(cell!=null || cell.getCellType() != HSSFCell.CELL_TYPE_BLANK){
//			            		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
//			            		record.setEducation(cell.getStringCellValue());
//			            	}
//			            	
//			            	//联系方式
//			            	cell = sheet.getRow(i).getCell(5);
//			            	if(cell!=null || cell.getCellType() != HSSFCell.CELL_TYPE_BLANK){
//			            		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
//			            		record.setPhone(cell.getStringCellValue());
//			            	}
//			            	
//			            	//就业状态
//			            	cell = sheet.getRow(i).getCell(6);
//			            	if(cell!=null || cell.getCellType() != HSSFCell.CELL_TYPE_BLANK){
//			            		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
//			            		record.setStatus(cell.getStringCellValue());
//			            	}
//			            	
//			            	//所在单位
//			            	cell = sheet.getRow(i).getCell(7);
//			            	if(cell!=null || cell.getCellType() != HSSFCell.CELL_TYPE_BLANK){
//			            		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
//			            		record.setCompany(cell.getStringCellValue());
//			            	}
//			            	
//			            	//失业时间
//			            	/*cell = sheet.getRow(i).getCell(8);
//			            	if(cell!=null || cell.getCellType() != HSSFCell.CELL_TYPE_BLANK){
//			            		cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
//			            		record.setUnemploymentdate(cell.getDateCellValue());
//			            	}*/
//			            	cell = sheet.getRow(i).getCell(8);
//			            	if(cell!=null || cell.getCellType() != HSSFCell.CELL_TYPE_BLANK){
//			            		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
//			            		record.setUnemploymentdate(cell.getStringCellValue());
//			            	}
//			            	
//			            	//街道
//			            	cell = sheet.getRow(i).getCell(7);
//			            	if(cell!=null || cell.getCellType() != HSSFCell.CELL_TYPE_BLANK){
//			            		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
//			            		record.setCompany(cell.getStringCellValue());
//			            	}
//			            	
//			            	//社区
//			            	cell = sheet.getRow(i).getCell(7);
//			            	if(cell!=null || cell.getCellType() != HSSFCell.CELL_TYPE_BLANK){
//			            		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
//			            		record.setCompany(cell.getStringCellValue());
//			            	}
//			            	
////			            	laborInfoService.saveLaborInfo(record);
//			            	for(int j=0;j<=colnum;j++){
//			            		cell = sheet.getRow(i).getCell(j);
//			            		if(cell==null){
//			            			System.out.print("\t\t");			            			
//			            		} else{
//			            			if(j==8)
//				            			System.out.print(df.format(cell.getDateCellValue())+"\t");
//				            		else{
//				            			cell.setCellType(HSSFCell.CELL_TYPE_STRING);
//						            	System.out.print(cell.getStringCellValue()+'\t');					            			
//				            		}			            			
//			            		}	            		
//			            	}
//			            	System.out.println();
//			            	
//			            } //for循环
//			            
//			            resultJson.setSuccess(ResultJson.SUCCESS_YES);
//			        	resultJson.setMessage("导入数据成功");
//			            	
//			    	} 
//			      }			    			    		
//			    }
//		} catch (FileUploadException e1) {
//			resultJson.setSuccess(ResultJson.SUCCESS_NO);
//			resultJson.setMessage(e1.getMessage());
//			e1.printStackTrace();
//			System.out.println("导入第"+i+"条数据时发生异常：FileUploadException");
//		} catch (IOException e1) {
//			resultJson.setSuccess(ResultJson.SUCCESS_NO);
//			resultJson.setMessage(e1.getMessage());
//			e1.printStackTrace();
//			System.out.println("导入第"+i+"条数据时发生异常：IOException");
//		} catch (Exception e1){
//			resultJson.setSuccess(ResultJson.SUCCESS_NO);
//			resultJson.setMessage(e1.getMessage());
//			e1.printStackTrace();
//			System.out.println("导入第"+i+"条数据时发生异常：Exception");		
//		} finally{
//			try {
//				result = mapper.writeValueAsString(resultJson);
//			}catch (IOException e) {
//				e.printStackTrace();
//				System.out.println("写入result信息时发生异常！");
//			}
////			return result;
//		}   			
//	}
	
	/**
	 * 根据主键删除一条劳动力信息记录
	 * @param Id
	 * @return
	 */
	@RequestMapping(value="/deleteLaborInfo", method = RequestMethod.POST)
	@ResponseBody
	public String deleteLaborInfo(@RequestParam("laborinfoId") String Id){
		String result = "";
		ResultJson resultJson = new ResultJson(); 
		try {
			laborInfoService.deleteByPrimaryKey(Id);
			resultJson.setSuccess(ResultJson.SUCCESS_YES);
			resultJson.setMessage(ResultJson.MESSAGE);
		} catch (Exception e) {
			resultJson.setSuccess(ResultJson.SUCCESS_NO);
			resultJson.setMessage("删除失败");
			e.printStackTrace();
		}finally{
			try {
				result = mapper.writeValueAsString(resultJson);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return result;
	}
	
	/**
	 * 根据主键laborinfoId查询一条劳动力信息记录
	 * @return
	 */
	@RequestMapping(value="/getLaborInfo", method = RequestMethod.POST)
	@ResponseBody
	public LaborInfoData getLaborInfo(@RequestParam("laborinfoId") String Id){
		LaborInfoData laborInfoData = new LaborInfoData();
		LaborInfoEntity laborInfoEntity = laborInfoService.selectByPrimaryKey(Id);
		laborInfoData.toEntityData(laborInfoData, laborInfoEntity);
		return laborInfoData;
	}
	
	/**
	 * 修改劳动力信息
	 * @return
	 */
	@RequestMapping(value="/updateLaborInfo", method = RequestMethod.POST)
	@ResponseBody
	public String updateLaborInfo(LaborInfoData record){
		String result = "";
		ResultJson resultJson = new ResultJson();
		LaborInfoEntity laborInfoEntity = new LaborInfoEntity();
		try {
			//将entity转化为实体类dto
			laborInfoEntity.toEntityData(laborInfoEntity, record, "");
			laborInfoService.updateLaborInfo(laborInfoEntity);
			resultJson.setSuccess(ResultJson.SUCCESS_YES);
			resultJson.setMessage(ResultJson.MESSAGE);
		} catch (Exception e) {
			resultJson.setSuccess(ResultJson.SUCCESS_NO);
			resultJson.setMessage("修改失败");
			e.printStackTrace();
		}finally{
			try {
				result = mapper.writeValueAsString(resultJson);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return result;
	}
	
	/**
	 * 修改失联人员信息
	 * @return
	 */
	@RequestMapping(value="/updateLoseTouchInfo", method = RequestMethod.POST)
	@ResponseBody
	public String updateLoseTouchInfo(LaborInfoData data){
		String result = "";
		ResultJson resultJson = new ResultJson();
		LaborInfoEntity laborInfoEntity = new LaborInfoEntity();
		try {
			//将entity转化为实体类dto
			laborInfoEntity.toEntityData(laborInfoEntity, data, "");
			laborInfoService.updateLoseTouch(laborInfoEntity);
			resultJson.setSuccess(ResultJson.SUCCESS_YES);
			resultJson.setMessage(ResultJson.MESSAGE);
		} catch (Exception e) {
			resultJson.setSuccess(ResultJson.SUCCESS_NO);
			resultJson.setMessage("修改失败");
			e.printStackTrace();
		}finally{
			try {
				result = mapper.writeValueAsString(resultJson);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return result;
	}
	
	/**
	 * 根据主键laborinfoId查询一条失联人员信息记录
	 * @return
	 */
	@RequestMapping(value="/getLoseTouchInfo", method = RequestMethod.POST)
	@ResponseBody
	public LaborInfoData getLoseTouchInfo(@RequestParam("laborinfoId") String Id){
		LaborInfoData laborInfoData = new LaborInfoData();
		LaborInfoEntity laborInfoEntity = laborInfoService.selectByPrimaryKey(Id);
		laborInfoData.toEntityData(laborInfoData, laborInfoEntity);
		return laborInfoData;
	}
}




